﻿
layui.config({
    base: '../../lib/layui/module/'
}).extend({
    treetable: 'treetable-lay/treetable'
}).use(['form', 'layedit', 'table', 'treetable'], function () {
    var form = layui.form
        , layer = layui.layer
        , table = layui.table
        , treetable = layui.treetable;
    // 渲染表格
    renderTable = function (param) {//树桩表格参考文档：https://gitee.com/whvse/treetable-lay
        layer.load(2);
        treetable.render({
            arrowType:'arrow2',
            treeColIndex: 2,//树形图标显示在第几列
            treeSpid: 0,//最上级的父级id
            treeIdName: 'id',//id字段的名称
            treePidName: 'parentTid',//pid字段的名称
            treeDefaultClose: false,//是否默认折叠
            treeLinkage: true,//父级展开时是否自动展开所有子级
            elem: '#menuTable',
            url: '/System/Menu/GetMenuList',
            where: param,
            page: false,
            cols: [[
                { field: 'id', hide: true, align: "center" },
                { type: 'numbers', title: '编号', align: "center", width:50 },
                {
                    field: 'name', title: '菜单名称',
                    templet: function () {
                       return "<span class='layui-badge layui-bg-blue'>菜单名称</span>";
                    }
                },
                { field: 'url', title: '菜单路径', align: "center" },
                {
                    field: 'orderRule', title: '排序', align: "center", width: 100
                },
                {
                    field: 'level', title: '类型', align: "center", width: 100,
                    templet: function (d) {
                        if (d.level == 1) {
                            return '一级菜单';
                        } else {
                            return '二级菜单';
                        }
                    }
                }, {
                    field: 'isActive', title: '是否启用', align: "center",
                    templet: function (d) {
                        if (d.isActive == 0) {
                            return "< span class='layui-badge'>禁用</span >";
                        } else {
                            return "<span class='layui-badge layui-bg-blue'>正常</span>";
                        }
                    }
                },
                { templet: complain, title: '操作', align: "center" }
            ]],
            done: function () {
                layer.closeAll('loading');
                $("span[lay-tpid!='0']").addClass("gkb-ml10");
            }
        });
    };
    renderTable();
    function complain(d) {//操作中显示的内容
        if (d.url != null) {
            return [
                '<button type="button" class="layui-btn layui-btn-sm" title="修改"><i class="iconfont gkb-xiugai-copy"></i></button>',
                '<button type="button" class="layui-btn layui-btn-sm layui-btn-danger" title="删除"><i class="iconfont gkb-shanchu"></i></button>',
            ].join('');
        } else {
            return '';
        }
    }
    $("#btn_foldAll").on("click", function () {
        treetable.foldAll('#menuTable');  // 折叠全部
    });
    $("#btn_search").on("click", function () {
        var data = form.val('searchForm');
        renderTable(data);
    })
});
